#include "ForcaMolas.h"
bool ForcaMolas::calculaMola(SPRING *k)
{
    REAL Dist, Dist2, F;
    REAL R[2], V[2];
    k->Translate();
    R[0] = k->R2[0] - k->R1[0];
    R[1] = k->R2[1] - k->R1[1];
    Dist2 = DOT( R, R );
    Dist = sqrt(Dist2);
    V[0] = k->S2->V[0] - k->S1->V[0];
    V[1] = k->S2->V[1] - k->S1->V[1];
    F = ( k->K * (k->L0 * Dist - Dist2) - k->C * DOT( V, R ) ) / Dist2;
    k->MeasureStress( Dist );
    if (k->Stress > k->Mat->Sigma_E) k->L0 += k->L0 * (k->Stress - k->Mat->Sigma_E) / k->Mat->Young;
    else if (-k->Stress > k->Mat->Sigma_E) k->L0 += k->L0 * (k->Stress + k->Mat->Sigma_E) / k->Mat->Young;
    k->S1->Force( -F, R );
    k->S2->Force( F, R );
    k->S1->Torque( -F * (PERP_DOT( R, k->R1 ) - PERP_DOT( R, k->S1->R )) );
    k->S2->Torque( F * (PERP_DOT( R, k->R2 ) - PERP_DOT( R, k->S2->R )) );
    if (Dist > k->FractureT || Dist < k->FractureC) return true;
    else return false;
}
